package com.amit.hibernate;
import java.util.List;
import org.hibernate.Filter;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

public class Lab41 {

	public static void main(String[] args) {
		
			
				SessionFactory sf=Chibernateutil.getFactory();
			
			Session session=sf.openSession();
			Transaction tx=session.beginTransaction();
			
			//2 show all customers
			System.out.println("All customers");
			displayAllCustomers(session);
			
			//3.Show Activated Customers
			Filter filter =session.enableFilter("StatusFilter");
			filter.setParameter("statusParam", "Active");
			System.out.println("Activated Customers");
             displayAllCustomers(session);		
             
             //4.show non-activated customers
             
             filter.setParameter("statusParam", "InActive");
 			System.out.println("Non-Activated Customers");
              displayAllCustomers(session);		
              
			tx.commit();
			session.close();
	}

	private static void displayAllCustomers(Session session) {
		
		Transaction trans=session.beginTransaction();
		Query query=session.createQuery("from Customer c");
		List<Customer> clist=query.list();
		
		for(Customer c:clist)
		{
			System.out.println(c);
		}
	}
}
